{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Brand</th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2006款 2.4 CVT 舒适型</td>\n",
       "      <td>2006年8月</td>\n",
       "      <td>9.00万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>6.90</td>\n",
       "      <td>50.89万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2007款 2.4 CVT 舒适型</td>\n",
       "      <td>2007年1月</td>\n",
       "      <td>8.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>8.88</td>\n",
       "      <td>50.89万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2004款 2.4L 技术领先型</td>\n",
       "      <td>2005年5月</td>\n",
       "      <td>15.00万公里</td>\n",
       "      <td>国2</td>\n",
       "      <td>3.82</td>\n",
       "      <td>54.24万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A8L 2013款 45 TFSI quattro舒适型</td>\n",
       "      <td>2013年10月</td>\n",
       "      <td>4.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>44.80</td>\n",
       "      <td>101.06万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2014款 30 FSI 豪华型</td>\n",
       "      <td>2014年9月</td>\n",
       "      <td>0.81万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>33.19</td>\n",
       "      <td>54.99万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Brand                            Name Boarding_time        Km Discharge  \\\n",
       "0    奥迪         奥迪A6L 2006款 2.4 CVT 舒适型       2006年8月   9.00万公里        国3   \n",
       "1    奥迪         奥迪A6L 2007款 2.4 CVT 舒适型       2007年1月   8.00万公里        国4   \n",
       "2    奥迪          奥迪A6L 2004款 2.4L 技术领先型       2005年5月  15.00万公里        国2   \n",
       "3    奥迪  奥迪A8L 2013款 45 TFSI quattro舒适型      2013年10月   4.80万公里        欧4   \n",
       "4    奥迪          奥迪A6L 2014款 30 FSI 豪华型       2014年9月   0.81万公里     国4,国5   \n",
       "\n",
       "   Sec_price New_price  \n",
       "0       6.90    50.89万  \n",
       "1       8.88    50.89万  \n",
       "2       3.82    54.24万  \n",
       "3      44.80   101.06万  \n",
       "4      33.19    54.99万  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1=pd.read_csv('second_cars_info_1.csv')\n",
    "data1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2=pd.read_csv('second_cars_info_2.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Brand</th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>道奇</td>\n",
       "      <td>酷威 2013款 2.4L 自动 两驱 智尚版</td>\n",
       "      <td>2015年8月</td>\n",
       "      <td>5.60万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>18.00</td>\n",
       "      <td>29.84万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>道奇</td>\n",
       "      <td>凯领 2007款 经典版</td>\n",
       "      <td>2008年8月</td>\n",
       "      <td>7.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>6.20</td>\n",
       "      <td>25.94万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>道奇</td>\n",
       "      <td>酷搏 2009款 2.0 运动型</td>\n",
       "      <td>2009年10月</td>\n",
       "      <td>6.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>7.58</td>\n",
       "      <td>23.87万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>道奇</td>\n",
       "      <td>酷威 2013款 2.4L 自动 两驱 尊尚版</td>\n",
       "      <td>2015年10月</td>\n",
       "      <td>1.53万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>18.80</td>\n",
       "      <td>31.68万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>道奇</td>\n",
       "      <td>酷威 2016款 2.4L 两驱 旅行版</td>\n",
       "      <td>2016年5月</td>\n",
       "      <td>1.80万公里</td>\n",
       "      <td>国5</td>\n",
       "      <td>16.49</td>\n",
       "      <td>32.55万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Brand                     Name Boarding_time       Km Discharge  Sec_price  \\\n",
       "0    道奇  酷威 2013款 2.4L 自动 两驱 智尚版       2015年8月  5.60万公里        欧4      18.00   \n",
       "1    道奇             凯领 2007款 经典版       2008年8月  7.00万公里        国4       6.20   \n",
       "2    道奇         酷搏 2009款 2.0 运动型      2009年10月  6.80万公里        欧4       7.58   \n",
       "3    道奇  酷威 2013款 2.4L 自动 两驱 尊尚版      2015年10月  1.53万公里        欧4      18.80   \n",
       "4    道奇     酷威 2016款 2.4L 两驱 旅行版       2016年5月  1.80万公里        国5      16.49   \n",
       "\n",
       "  New_price  \n",
       "0    29.84万  \n",
       "1    25.94万  \n",
       "2    23.87万  \n",
       "3    31.68万  \n",
       "4    32.55万  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(11281, 7)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据合并\n",
    "import pandas as pd\n",
    "data1=pd.read_csv('second_cars_info_1.csv')\n",
    "data2=pd.read_csv('second_cars_info_2.csv')\n",
    "#使用concat纵向合并数据\n",
    "data = pd.concat([data1,data2],axis=0)\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Brand                            Name  Sec_price New_price\n",
      "0    奥迪         奥迪A6L 2006款 2.4 CVT 舒适型       6.90    50.89万\n",
      "1    奥迪         奥迪A6L 2007款 2.4 CVT 舒适型       8.88    50.89万\n",
      "2    奥迪          奥迪A6L 2004款 2.4L 技术领先型       3.82    54.24万\n",
      "3    奥迪  奥迪A8L 2013款 45 TFSI quattro舒适型      44.80   101.06万\n",
      "4    奥迪          奥迪A6L 2014款 30 FSI 豪华型      33.19    54.99万\n",
      "(5, 4)\n"
     ]
    }
   ],
   "source": [
    "data1 = data.iloc[0:5,0:2]#获取前5条前2列数据\n",
    "data2 = data.iloc[0:5,-2:]#获取前5条后2列数据\n",
    "#使用concat纵向合并数据\n",
    "new_data = pd.concat([data1,data2],axis=1)\n",
    "print(new_data)\n",
    "print(new_data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     Brand Boarding_time        Km Discharge  Sec_price New_price\n",
      "0       奥迪       2006年8月   9.00万公里        国3       6.90    50.89万\n",
      "1       奥迪       2007年1月   8.00万公里        国4       8.88    50.89万\n",
      "2       奥迪       2005年5月  15.00万公里        国2       3.82    54.24万\n",
      "3       奥迪      2013年10月   4.80万公里        欧4      44.80   101.06万\n",
      "4       奥迪       2014年9月   0.81万公里     国4,国5      33.19    54.99万\n",
      "...    ...           ...       ...       ...        ...       ...\n",
      "5292    中华       2016年6月   1.90万公里     国4,国5       7.00     9.63万\n",
      "5293    中华       2011年6月   5.00万公里        国4       2.20     6.22万\n",
      "5294    中华      2007年10月   8.50万公里        国3       1.80    11.48万\n",
      "5295    中华      2011年12月   7.80万公里        国4       2.10     8.99万\n",
      "5296  中欧房车       2014年4月   6.80万公里        欧4      53.80   168.25万\n",
      "\n",
      "[11281 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "#删除含空值的列，若按行删除可以指定axis=0\n",
    "data_noname=data.drop(labels= 'Name',axis=1,inplace=False)\n",
    "print(data_noname)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0      NaN\n",
      "1     9.88\n",
      "2     4.82\n",
      "3    45.80\n",
      "4    34.19\n",
      "Name: Sec_price2, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "#新增一列Sec_price2，值为在原来Sec_price的基础上加1\n",
    "data[\"Sec_price2\"] = data[\"Sec_price\"]+1\n",
    "print(data[\"Sec_price2\"].head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据去重\n",
    "dishes_data1=data.drop_duplicates()\n",
    "dishes_data1.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除法处理缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        6.90\n",
       "1        8.88\n",
       "2        3.82\n",
       "3       44.80\n",
       "4       33.19\n",
       "        ...  \n",
       "5292     7.00\n",
       "5293     2.20\n",
       "5294     1.80\n",
       "5295     2.10\n",
       "5296    53.80\n",
       "Name: Sec_price, Length: 11178, dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data111=data['Sec_price'].dropna(axis=0)\n",
    "data111"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00824395000443223\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Brand</th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2006款 2.4 CVT 舒适型</td>\n",
       "      <td>2006年8月</td>\n",
       "      <td>9.00万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>6.90</td>\n",
       "      <td>50.89万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2007款 2.4 CVT 舒适型</td>\n",
       "      <td>2007年1月</td>\n",
       "      <td>8.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>8.88</td>\n",
       "      <td>50.89万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2004款 2.4L 技术领先型</td>\n",
       "      <td>2005年5月</td>\n",
       "      <td>15.00万公里</td>\n",
       "      <td>国2</td>\n",
       "      <td>3.82</td>\n",
       "      <td>54.24万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A8L 2013款 45 TFSI quattro舒适型</td>\n",
       "      <td>2013年10月</td>\n",
       "      <td>4.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>44.80</td>\n",
       "      <td>101.06万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2014款 30 FSI 豪华型</td>\n",
       "      <td>2014年9月</td>\n",
       "      <td>0.81万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>33.19</td>\n",
       "      <td>54.99万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5292</th>\n",
       "      <td>中华</td>\n",
       "      <td>中华V3 2016款 1.5L 自动 智能型</td>\n",
       "      <td>2016年6月</td>\n",
       "      <td>1.90万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>7.00</td>\n",
       "      <td>9.63万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5293</th>\n",
       "      <td>中华</td>\n",
       "      <td>骏捷FRV 2010款 1.3MT 舒适型</td>\n",
       "      <td>2011年6月</td>\n",
       "      <td>5.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>2.20</td>\n",
       "      <td>6.22万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5294</th>\n",
       "      <td>中华</td>\n",
       "      <td>骏捷 2007款 1.8 MT 豪华型</td>\n",
       "      <td>2007年10月</td>\n",
       "      <td>8.50万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>1.80</td>\n",
       "      <td>11.48万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5295</th>\n",
       "      <td>中华</td>\n",
       "      <td>骏捷FSV 2010款 1.5MT精英型</td>\n",
       "      <td>2011年12月</td>\n",
       "      <td>7.80万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>2.10</td>\n",
       "      <td>8.99万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5296</th>\n",
       "      <td>中欧房车</td>\n",
       "      <td>尊逸 2013款 3.5L 尊逸A型</td>\n",
       "      <td>2014年4月</td>\n",
       "      <td>6.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>53.80</td>\n",
       "      <td>168.25万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>11188 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Brand                            Name Boarding_time        Km Discharge  \\\n",
       "0       奥迪         奥迪A6L 2006款 2.4 CVT 舒适型       2006年8月   9.00万公里        国3   \n",
       "1       奥迪         奥迪A6L 2007款 2.4 CVT 舒适型       2007年1月   8.00万公里        国4   \n",
       "2       奥迪          奥迪A6L 2004款 2.4L 技术领先型       2005年5月  15.00万公里        国2   \n",
       "3       奥迪  奥迪A8L 2013款 45 TFSI quattro舒适型      2013年10月   4.80万公里        欧4   \n",
       "4       奥迪          奥迪A6L 2014款 30 FSI 豪华型       2014年9月   0.81万公里     国4,国5   \n",
       "...    ...                             ...           ...       ...       ...   \n",
       "5292    中华          中华V3 2016款 1.5L 自动 智能型       2016年6月   1.90万公里     国4,国5   \n",
       "5293    中华           骏捷FRV 2010款 1.3MT 舒适型       2011年6月   5.00万公里        国4   \n",
       "5294    中华             骏捷 2007款 1.8 MT 豪华型      2007年10月   8.50万公里        国3   \n",
       "5295    中华            骏捷FSV 2010款 1.5MT精英型      2011年12月   7.80万公里        国4   \n",
       "5296  中欧房车              尊逸 2013款 3.5L 尊逸A型       2014年4月   6.80万公里        欧4   \n",
       "\n",
       "      Sec_price New_price  \n",
       "0          6.90    50.89万  \n",
       "1          8.88    50.89万  \n",
       "2          3.82    54.24万  \n",
       "3         44.80   101.06万  \n",
       "4         33.19    54.99万  \n",
       "...         ...       ...  \n",
       "5292       7.00     9.63万  \n",
       "5293       2.20     6.22万  \n",
       "5294       1.80    11.48万  \n",
       "5295       2.10     8.99万  \n",
       "5296      53.80   168.25万  \n",
       "\n",
       "[11188 rows x 7 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除法处理缺失值---Boarding_time\n",
    "# 1）统计Boarding_time列未上牌的数据\n",
    "coun=data[data.Boarding_time=='未上牌'].count()[0]\n",
    "r=coun/data.shape[0]\n",
    "print(r)\n",
    "# 由于未上牌的汽车输血量占比极少，仅占千分之八，这里可以考虑将其行删除\n",
    "car_data=data.loc[data.Boarding_time!='未上牌',:]\n",
    "car_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#替换法处理缺失值\n",
    "\n",
    "#使用固定值填充数据集中所有的缺失值\n",
    "data3=data[\"Sec_price\"].fillna(-1)\n",
    "#使用均值填充age中的缺失值\n",
    "data3=data[\"Sec_price\"].fillna(data[\"Sec_price\"].mean())\n",
    "#使用上一个非缺失值填充age中的缺失值\n",
    "data3=data[\"Sec_price\"].fillna(method='pad')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-18-9e2ca02a49c0>:6: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  car_data['year']=car_data.Boarding_time.str[:4].astype('int')\n",
      "<ipython-input-18-9e2ca02a49c0>:8: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  car_data['month']=car_data.Boarding_time.str.extract('年([0-9]*)月',expand=False)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Brand</th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2006款 2.4 CVT 舒适型</td>\n",
       "      <td>2006年8月</td>\n",
       "      <td>9.00万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>6.90</td>\n",
       "      <td>50.89万</td>\n",
       "      <td>2006</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2007款 2.4 CVT 舒适型</td>\n",
       "      <td>2007年1月</td>\n",
       "      <td>8.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>8.88</td>\n",
       "      <td>50.89万</td>\n",
       "      <td>2007</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2004款 2.4L 技术领先型</td>\n",
       "      <td>2005年5月</td>\n",
       "      <td>15.00万公里</td>\n",
       "      <td>国2</td>\n",
       "      <td>3.82</td>\n",
       "      <td>54.24万</td>\n",
       "      <td>2005</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A8L 2013款 45 TFSI quattro舒适型</td>\n",
       "      <td>2013年10月</td>\n",
       "      <td>4.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>44.80</td>\n",
       "      <td>101.06万</td>\n",
       "      <td>2013</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>奥迪</td>\n",
       "      <td>奥迪A6L 2014款 30 FSI 豪华型</td>\n",
       "      <td>2014年9月</td>\n",
       "      <td>0.81万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>33.19</td>\n",
       "      <td>54.99万</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Brand                            Name Boarding_time        Km Discharge  \\\n",
       "0    奥迪         奥迪A6L 2006款 2.4 CVT 舒适型       2006年8月   9.00万公里        国3   \n",
       "1    奥迪         奥迪A6L 2007款 2.4 CVT 舒适型       2007年1月   8.00万公里        国4   \n",
       "2    奥迪          奥迪A6L 2004款 2.4L 技术领先型       2005年5月  15.00万公里        国2   \n",
       "3    奥迪  奥迪A8L 2013款 45 TFSI quattro舒适型      2013年10月   4.80万公里        欧4   \n",
       "4    奥迪          奥迪A6L 2014款 30 FSI 豪华型       2014年9月   0.81万公里     国4,国5   \n",
       "\n",
       "   Sec_price New_price  year month  \n",
       "0       6.90    50.89万  2006     8  \n",
       "1       8.88    50.89万  2007     1  \n",
       "2       3.82    54.24万  2005     5  \n",
       "3      44.80   101.06万  2013    10  \n",
       "4      33.19    54.99万  2014     9  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 年月分割开\n",
    "import re\n",
    "# 重置索引\n",
    "car_data.index=range(0,car_data.shape[0])\n",
    "# 分割出年份\n",
    "car_data['year']=car_data.Boarding_time.str[:4].astype('int')\n",
    "# 分割出月份\n",
    "car_data['month']=car_data.Boarding_time.str.extract('年([0-9]*)月',expand=False)\n",
    "car_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>Brand_DS</th>\n",
       "      <th>Brand_GMC</th>\n",
       "      <th>...</th>\n",
       "      <th>Brand_长安</th>\n",
       "      <th>Brand_长安欧尚</th>\n",
       "      <th>Brand_阿尔法·罗密欧</th>\n",
       "      <th>Brand_阿斯顿·马丁</th>\n",
       "      <th>Brand_陆风</th>\n",
       "      <th>Brand_雪佛兰</th>\n",
       "      <th>Brand_雪铁龙</th>\n",
       "      <th>Brand_雷克萨斯</th>\n",
       "      <th>Brand_雷诺</th>\n",
       "      <th>Brand_马自达</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>奥迪A6L 2006款 2.4 CVT 舒适型</td>\n",
       "      <td>2006年8月</td>\n",
       "      <td>9.00</td>\n",
       "      <td>国3</td>\n",
       "      <td>6.90</td>\n",
       "      <td>50.89</td>\n",
       "      <td>2006</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪A6L 2007款 2.4 CVT 舒适型</td>\n",
       "      <td>2007年1月</td>\n",
       "      <td>8.00</td>\n",
       "      <td>国4</td>\n",
       "      <td>8.88</td>\n",
       "      <td>50.89</td>\n",
       "      <td>2007</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>奥迪A6L 2004款 2.4L 技术领先型</td>\n",
       "      <td>2005年5月</td>\n",
       "      <td>15.00</td>\n",
       "      <td>国2</td>\n",
       "      <td>3.82</td>\n",
       "      <td>54.24</td>\n",
       "      <td>2005</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>奥迪A8L 2013款 45 TFSI quattro舒适型</td>\n",
       "      <td>2013年10月</td>\n",
       "      <td>4.80</td>\n",
       "      <td>欧4</td>\n",
       "      <td>44.80</td>\n",
       "      <td>101.06</td>\n",
       "      <td>2013</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>奥迪A6L 2014款 30 FSI 豪华型</td>\n",
       "      <td>2014年9月</td>\n",
       "      <td>0.81</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>33.19</td>\n",
       "      <td>54.99</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Name Boarding_time     Km Discharge  Sec_price  \\\n",
       "0         奥迪A6L 2006款 2.4 CVT 舒适型       2006年8月   9.00        国3       6.90   \n",
       "1         奥迪A6L 2007款 2.4 CVT 舒适型       2007年1月   8.00        国4       8.88   \n",
       "2          奥迪A6L 2004款 2.4L 技术领先型       2005年5月  15.00        国2       3.82   \n",
       "3  奥迪A8L 2013款 45 TFSI quattro舒适型      2013年10月   4.80        欧4      44.80   \n",
       "4          奥迪A6L 2014款 30 FSI 豪华型       2014年9月   0.81     国4,国5      33.19   \n",
       "\n",
       "  New_price  year month  Brand_DS  Brand_GMC  ...  Brand_长安  Brand_长安欧尚  \\\n",
       "0     50.89  2006     8         0          0  ...         0           0   \n",
       "1     50.89  2007     1         0          0  ...         0           0   \n",
       "2     54.24  2005     5         0          0  ...         0           0   \n",
       "3    101.06  2013    10         0          0  ...         0           0   \n",
       "4     54.99  2014     9         0          0  ...         0           0   \n",
       "\n",
       "   Brand_阿尔法·罗密欧  Brand_阿斯顿·马丁  Brand_陆风  Brand_雪佛兰  Brand_雪铁龙  Brand_雷克萨斯  \\\n",
       "0              0             0         0          0          0           0   \n",
       "1              0             0         0          0          0           0   \n",
       "2              0             0         0          0          0           0   \n",
       "3              0             0         0          0          0           0   \n",
       "4              0             0         0          0          0           0   \n",
       "\n",
       "   Brand_雷诺  Brand_马自达  \n",
       "0         0          0  \n",
       "1         0          0  \n",
       "2         0          0  \n",
       "3         0          0  \n",
       "4         0          0  \n",
       "\n",
       "[5 rows x 112 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 去除计价单位\n",
    "car_data['New_price']=car_data.New_price.str.extract('(\\d*\\.\\d*)万',expand=True)\n",
    "car_data['Km']=car_data.Km.str.extract('(\\d*\\.\\d*)万公里',expand=True)\n",
    "car_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字段数据类型转换\n",
    "car_data.dtypes\n",
    "car_data['New_price']=car_data['New_price'].astype('float')\n",
    "car_data['Sec_price']=car_data['Sec_price'].astype('float')\n",
    "car_data['Km']=car_data['Km'].astype('float')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      Brand_DS  Brand_GMC  Brand_Jeep  Brand_MINI  Brand_WEY  Brand_smart  \\\n",
      "0            0          0           0           0          0            0   \n",
      "1            0          0           0           0          0            0   \n",
      "2            0          0           0           0          0            0   \n",
      "3            0          0           0           0          0            0   \n",
      "4            0          0           0           0          0            0   \n",
      "...        ...        ...         ...         ...        ...          ...   \n",
      "5292         0          0           0           0          0            0   \n",
      "5293         0          0           0           0          0            0   \n",
      "5294         0          0           0           0          0            0   \n",
      "5295         0          0           0           0          0            0   \n",
      "5296         0          0           0           0          0            0   \n",
      "\n",
      "      Brand_一汽  Brand_三菱  Brand_上汽大通  Brand_世爵  ...  Brand_长安  Brand_长安欧尚  \\\n",
      "0            0         0           0         0  ...         0           0   \n",
      "1            0         0           0         0  ...         0           0   \n",
      "2            0         0           0         0  ...         0           0   \n",
      "3            0         0           0         0  ...         0           0   \n",
      "4            0         0           0         0  ...         0           0   \n",
      "...        ...       ...         ...       ...  ...       ...         ...   \n",
      "5292         0         0           0         0  ...         0           0   \n",
      "5293         0         0           0         0  ...         0           0   \n",
      "5294         0         0           0         0  ...         0           0   \n",
      "5295         0         0           0         0  ...         0           0   \n",
      "5296         0         0           0         0  ...         0           0   \n",
      "\n",
      "      Brand_阿尔法·罗密欧  Brand_阿斯顿·马丁  Brand_陆风  Brand_雪佛兰  Brand_雪铁龙  Brand_雷克萨斯  \\\n",
      "0                 0             0         0          0          0           0   \n",
      "1                 0             0         0          0          0           0   \n",
      "2                 0             0         0          0          0           0   \n",
      "3                 0             0         0          0          0           0   \n",
      "4                 0             0         0          0          0           0   \n",
      "...             ...           ...       ...        ...        ...         ...   \n",
      "5292              0             0         0          0          0           0   \n",
      "5293              0             0         0          0          0           0   \n",
      "5294              0             0         0          0          0           0   \n",
      "5295              0             0         0          0          0           0   \n",
      "5296              0             0         0          0          0           0   \n",
      "\n",
      "      Brand_雷诺  Brand_马自达  \n",
      "0            0          0  \n",
      "1            0          0  \n",
      "2            0          0  \n",
      "3            0          0  \n",
      "4            0          0  \n",
      "...        ...        ...  \n",
      "5292         0          0  \n",
      "5293         0          0  \n",
      "5294         0          0  \n",
      "5295         0          0  \n",
      "5296         0          0  \n",
      "\n",
      "[11281 rows x 104 columns]\n"
     ]
    }
   ],
   "source": [
    "#使用哑变量转换数据\n",
    "Brand_dummies = pd.get_dummies(data['Brand'],prefix='Brand')\n",
    "print(Brand_dummies)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Boarding_time</th>\n",
       "      <th>Km</th>\n",
       "      <th>Discharge</th>\n",
       "      <th>Sec_price</th>\n",
       "      <th>New_price</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>Brand_DS</th>\n",
       "      <th>Brand_GMC</th>\n",
       "      <th>...</th>\n",
       "      <th>Brand_长安</th>\n",
       "      <th>Brand_长安欧尚</th>\n",
       "      <th>Brand_阿尔法·罗密欧</th>\n",
       "      <th>Brand_阿斯顿·马丁</th>\n",
       "      <th>Brand_陆风</th>\n",
       "      <th>Brand_雪佛兰</th>\n",
       "      <th>Brand_雪铁龙</th>\n",
       "      <th>Brand_雷克萨斯</th>\n",
       "      <th>Brand_雷诺</th>\n",
       "      <th>Brand_马自达</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>奥迪A6L 2006款 2.4 CVT 舒适型</td>\n",
       "      <td>2006年8月</td>\n",
       "      <td>9.00万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>6.90</td>\n",
       "      <td>50.89万</td>\n",
       "      <td>2006</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪A6L 2007款 2.4 CVT 舒适型</td>\n",
       "      <td>2007年1月</td>\n",
       "      <td>8.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>8.88</td>\n",
       "      <td>50.89万</td>\n",
       "      <td>2007</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>奥迪A6L 2004款 2.4L 技术领先型</td>\n",
       "      <td>2005年5月</td>\n",
       "      <td>15.00万公里</td>\n",
       "      <td>国2</td>\n",
       "      <td>3.82</td>\n",
       "      <td>54.24万</td>\n",
       "      <td>2005</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>奥迪A8L 2013款 45 TFSI quattro舒适型</td>\n",
       "      <td>2013年10月</td>\n",
       "      <td>4.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>44.80</td>\n",
       "      <td>101.06万</td>\n",
       "      <td>2013</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>奥迪A6L 2014款 30 FSI 豪华型</td>\n",
       "      <td>2014年9月</td>\n",
       "      <td>0.81万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>33.19</td>\n",
       "      <td>54.99万</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11183</th>\n",
       "      <td>中华V3 2016款 1.5L 自动 智能型</td>\n",
       "      <td>2016年6月</td>\n",
       "      <td>1.90万公里</td>\n",
       "      <td>国4,国5</td>\n",
       "      <td>7.00</td>\n",
       "      <td>9.63万</td>\n",
       "      <td>2016</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11184</th>\n",
       "      <td>骏捷FRV 2010款 1.3MT 舒适型</td>\n",
       "      <td>2011年6月</td>\n",
       "      <td>5.00万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>2.20</td>\n",
       "      <td>6.22万</td>\n",
       "      <td>2011</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11185</th>\n",
       "      <td>骏捷 2007款 1.8 MT 豪华型</td>\n",
       "      <td>2007年10月</td>\n",
       "      <td>8.50万公里</td>\n",
       "      <td>国3</td>\n",
       "      <td>1.80</td>\n",
       "      <td>11.48万</td>\n",
       "      <td>2007</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11186</th>\n",
       "      <td>骏捷FSV 2010款 1.5MT精英型</td>\n",
       "      <td>2011年12月</td>\n",
       "      <td>7.80万公里</td>\n",
       "      <td>国4</td>\n",
       "      <td>2.10</td>\n",
       "      <td>8.99万</td>\n",
       "      <td>2011</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11187</th>\n",
       "      <td>尊逸 2013款 3.5L 尊逸A型</td>\n",
       "      <td>2014年4月</td>\n",
       "      <td>6.80万公里</td>\n",
       "      <td>欧4</td>\n",
       "      <td>53.80</td>\n",
       "      <td>168.25万</td>\n",
       "      <td>2014</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>11188 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Name Boarding_time        Km Discharge  \\\n",
       "0             奥迪A6L 2006款 2.4 CVT 舒适型       2006年8月   9.00万公里        国3   \n",
       "1             奥迪A6L 2007款 2.4 CVT 舒适型       2007年1月   8.00万公里        国4   \n",
       "2              奥迪A6L 2004款 2.4L 技术领先型       2005年5月  15.00万公里        国2   \n",
       "3      奥迪A8L 2013款 45 TFSI quattro舒适型      2013年10月   4.80万公里        欧4   \n",
       "4              奥迪A6L 2014款 30 FSI 豪华型       2014年9月   0.81万公里     国4,国5   \n",
       "...                               ...           ...       ...       ...   \n",
       "11183          中华V3 2016款 1.5L 自动 智能型       2016年6月   1.90万公里     国4,国5   \n",
       "11184           骏捷FRV 2010款 1.3MT 舒适型       2011年6月   5.00万公里        国4   \n",
       "11185             骏捷 2007款 1.8 MT 豪华型      2007年10月   8.50万公里        国3   \n",
       "11186            骏捷FSV 2010款 1.5MT精英型      2011年12月   7.80万公里        国4   \n",
       "11187              尊逸 2013款 3.5L 尊逸A型       2014年4月   6.80万公里        欧4   \n",
       "\n",
       "       Sec_price New_price  year month  Brand_DS  Brand_GMC  ...  Brand_长安  \\\n",
       "0           6.90    50.89万  2006     8         0          0  ...         0   \n",
       "1           8.88    50.89万  2007     1         0          0  ...         0   \n",
       "2           3.82    54.24万  2005     5         0          0  ...         0   \n",
       "3          44.80   101.06万  2013    10         0          0  ...         0   \n",
       "4          33.19    54.99万  2014     9         0          0  ...         0   \n",
       "...          ...       ...   ...   ...       ...        ...  ...       ...   \n",
       "11183       7.00     9.63万  2016     6         0          0  ...         0   \n",
       "11184       2.20     6.22万  2011     6         0          0  ...         0   \n",
       "11185       1.80    11.48万  2007    10         0          0  ...         0   \n",
       "11186       2.10     8.99万  2011    12         0          0  ...         0   \n",
       "11187      53.80   168.25万  2014     4         0          0  ...         0   \n",
       "\n",
       "       Brand_长安欧尚  Brand_阿尔法·罗密欧  Brand_阿斯顿·马丁  Brand_陆风  Brand_雪佛兰  \\\n",
       "0               0              0             0         0          0   \n",
       "1               0              0             0         0          0   \n",
       "2               0              0             0         0          0   \n",
       "3               0              0             0         0          0   \n",
       "4               0              0             0         0          0   \n",
       "...           ...            ...           ...       ...        ...   \n",
       "11183           0              0             0         0          0   \n",
       "11184           0              0             0         0          0   \n",
       "11185           0              0             0         0          0   \n",
       "11186           0              0             0         0          0   \n",
       "11187           0              0             0         0          0   \n",
       "\n",
       "       Brand_雪铁龙  Brand_雷克萨斯  Brand_雷诺  Brand_马自达  \n",
       "0              0           0         0          0  \n",
       "1              0           0         0          0  \n",
       "2              0           0         0          0  \n",
       "3              0           0         0          0  \n",
       "4              0           0         0          0  \n",
       "...          ...         ...       ...        ...  \n",
       "11183          0           0         0          0  \n",
       "11184          0           0         0          0  \n",
       "11185          0           0         0          0  \n",
       "11186          0           0         0          0  \n",
       "11187          0           0         0          0  \n",
       "\n",
       "[11188 rows x 112 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "car_data=pd.get_dummies(car_data,prefix='Brand',columns=['Brand'])\n",
    "car_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据保存\n",
    "car_data.to_csv('new_car_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
